﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LibrarySolution.DAO.基础;
using LibrarySolution.Model.基础;
using LibrarySolution.ComMethod;

namespace LibrarySolution.Frm
{
    public partial class FrmPeLo : Form
    {
        #region 属性
        private static FrmPeLo Instance;
        YhDao yhDao;
        YhxxEntity yhxxEntity;
        #endregion

        #region 构造器
        public FrmPeLo()
        {
            InitializeComponent();
        }
        #endregion

        #region 事件
        public static FrmPeLo GetInstance()
        {
            if (Instance == null || Instance.IsDisposed)
            {
                Instance = new FrmPeLo();
                Instance.SendToBack();
                Instance.MdiParent = GlobalVar.frmMain;
                GlobalVar.frmMain.panel1.Controls.Add(Instance);
                Instance.BringToFront();
            }
            return Instance;
        }

        private void BtnDone_Click(object sender, EventArgs e)
        {
            yhDao = new YhDao();
            String yhPwd = yhDao.getYhPwdByNo(TxtSearchByYhNo.Text);
            if (!String.IsNullOrEmpty(yhPwd))
            {
                GlobalVar.YhEnter = true;
                yhxxEntity = new YhxxEntity();
                yhxxEntity.yh_no = TxtSearchByYhNo.Text;
                yhxxEntity.yh_pwd = yhPwd;
                GlobalVar.YhxxEntity = yhxxEntity;
                FrmChangPwd.GetInstance(TxtSearchByYhNo.Text).Show();
                GlobalVar.YhEnter = true;
                this.Close();
                return;
            }
            else
            {
                if (GlobalVar.YhEnter == true) return;
                GlyDao glyDao = new GlyDao();
                yhPwd = glyDao.getYhPwdByNo(TxtSearchByYhNo.Text);
                if (!String.IsNullOrEmpty(yhPwd))
                {
                    GlobalVar.YhEnter = false;
                    GlyEntity glyEntity = new GlyEntity();
                    glyEntity.gly_pwd = yhPwd;
                    glyEntity.gly_zh = TxtSearchByYhNo.Text;
                    glyEntity.gly_code = glyDao.getGlyCodeByZh(TxtSearchByYhNo.Text);
                    GlobalVar.GlyEntity = glyEntity;
                    FrmChangPwd.GetInstance(TxtSearchByYhNo.Text).Show();
                    this.Close();
                    return;
                }
            }
            MessageBox.Show("用户不存在或已被查封");
        }

        private void TxtSearchByYhNo_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(Char.IsNumber(e.KeyChar) || e.KeyChar == '\b'))
                e.Handled = true;
        }

        private void BtnCancle_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion
    }
}
